#include "user_global.h"
#include "modbus.h"

#if FILE_COUNT

ushort xdata file_buf[FILE_BUFFER_SIZE] = {0};

FILE_DESC files[FILE_COUNT] =
{
    { FILE_BUFFER_MASK, FILE_BUFFER_SIZE, file_buf },
};

//void Reset_File(uchar fid)
//{ 
//  FILE_DESC *f = &files[fid];
//  f->count = 0;
//}

//void Append_File(uchar fid, ushort *rec, ushort n)
//{
//  FILE_DESC *f = &files[fid];

//  while(n--)
//      f->ptr.w[f->mask & f->count++] = *rec++;
//}

ushort Read_File(uchar fid, ushort addr)
{
    FILE_DESC *f = &files[fid];
    return f->ptr.w[addr & f->mask];
}

void Write_File(uchar fid, ushort addr, ushort val)
{
    FILE_DESC *f = &files[fid];
    f->ptr.w[addr & f->mask] = val;
}

ushort File_Size(uchar fid)
{
    FILE_DESC *f = &files[fid];
    return f->count;
}

#endif
